package com.smzd.ccms.domain;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.smzd.core.domain.BaseScopeEntity;
import com.smzd.framework.annotation.ModuleGroup;

@ModuleGroup(value = "ccms/admin", moduleNames = "completcfgs", moduleName = "completcfg")
public class CompletConfig extends BaseScopeEntity<ChannelConfig> {
	private static final long serialVersionUID = -1523560492211325534L;
	// 空穴编号
	private Integer spotid;
	// 模块
	private Complet complet;

	// 新指定的参数值获取方式配置
	private Map<String, CompletParamConfig> cpConfigs;

	/**
	 * 获取空穴编号
	 * 
	 * @return
	 */
	public Integer getSpotid() {
		return spotid;
	}

	/**
	 * 设置空穴编号
	 * 
	 * @param spotid
	 */
	public void setSpotid(Integer spotid) {
		this.spotid = spotid;
	}

	/**
	 * 获取模块
	 * 
	 * @return
	 */
	public Complet getComplet() {
		return complet;
	}

	/**
	 * 设置模块
	 * 
	 * @param complet
	 */
	public void setComplet(Complet complet) {
		this.complet = complet;
	}

	public Map<String, CompletParamConfig> getCpConfigs() {
		return cpConfigs;
	}

	public void putCpConfigs(List<CompletParamConfig> cpConfigs) {
		for (CompletParamConfig cpc : cpConfigs) {
			putCpConfig(cpc);
		}
	}

	public CompletParamConfig getCpConfig(String key) {
		return cpConfigs == null ? null : cpConfigs.get(key);
	}
	
	public <T> T getCompletDefaultParamValue(String key){
		return complet.getDefaultParamValue(key);
	}

	@SuppressWarnings("unchecked")
	public <T> T getDefaultParamValue(String key) {
		if (cpConfigs == null) {
			return complet.getDefaultParamValue(key);
		}
		CompletParamConfig cpc = cpConfigs.get(key);
		if (cpc != null) {
			return (T) cpc.varValue();
		}
		return complet.getDefaultParamValue(key);
	}

	public void putCpConfig(CompletParamConfig cpConfig) {
		if (cpConfigs == null) {
			cpConfigs = new HashMap<String, CompletParamConfig>();
		}
		cpConfigs.put(cpConfig.getKey(), cpConfig);
	}
}